package cn.exrick.xboot.core.base

import cn.exrick.xboot.core.common.constant.CommonConstant
import cn.exrick.xboot.core.common.utils.SnowFlakeUtil
import com.baomidou.mybatisplus.annotation.FieldFill
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableLogic
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
import lombok.Data
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import org.springframework.format.annotation.DateTimeFormat
import java.io.Serializable
import java.util.*
import javax.persistence.EntityListeners
import javax.persistence.Id
import javax.persistence.MappedSuperclass

@EntityListeners(AuditingEntityListener::class)
@JsonIgnoreProperties(value = ["hibernateLazyInitializer", "handler", "fieldHandler"])
@ApiModel("基础实体")
@Data
@MappedSuperclass
open class XbootBaseEntityKt : Serializable {

    companion object {

        const val serialVersionUID: Long = 1L
    }

    @Id
    @TableId
    @ApiModelProperty("id", hidden = true)
    open var id: String = SnowFlakeUtil.nextId().toString()

    @ApiModelProperty("创建者")
    @TableField(fill = FieldFill.INSERT)
    var createBy: String = ""

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间", hidden = true)
    @TableField(fill = FieldFill.INSERT)
    var createTime: Date? = null


    @ApiModelProperty(value = "更新者", hidden = true)
    @TableField(fill = FieldFill.UPDATE)
    var updateBy: String= ""

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间", hidden = true)
    @TableField(fill = FieldFill.UPDATE)
    var updateTime: Date? = null

    @TableLogic
    @ApiModelProperty(value = "删除标志 默认0", hidden = true)
    var delFlag:Int = CommonConstant.STATUS_NORMAL
}